import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

class Footlistcomp extends StatefulWidget {
  const Footlistcomp({super.key});

  @override
  State<Footlistcomp> createState() => _FootlistcompState();
}

class _FootlistcompState extends State<Footlistcomp> {
  List foods = [];
  @override

//数据请求
  initState() {
    super.initState();
    getFood();
  }

  getFood() async {
    Dio dio = Dio();
    // 基础地址
    dio.options.baseUrl = 'https://zhousg.atomgit.net';
    final response = await dio.get('/harmonyos5/takeaway.json');
    setState(() {
      //必须加setState去响应UI更新，因为这个方法是异步的会先走下面
      foods = response.data as List;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: double.infinity,
      color: Colors.grey[200],

      //左列表
      child: ListView.builder(
        itemBuilder: (context, item) {
          return Container(
            alignment: Alignment.centerLeft,
            color: Colors.grey,
            child: Text(
              foods[item]['name'],
              style: const TextStyle(color: Colors.black),
            ),
          );
        },
        itemCount: foods.length,
      ),
      //右列表
    );
  }
}
